/*
 * COPYRIGHT. ShenZhen iByte Technology Co., Ltd. 2018.
 * ALL RIGHTS RESERVED.
 *
 * No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
 * on any form or by any means, electronic, mechanical, photocopying, recording, 
 * or otherwise, without the prior written permission of ShenZhen iByte Network Technology Co., Ltd.
 *
 * Amendment History:
 * 
 * Date                   By              Description
 * -------------------    -----------     -------------------------------------------
 * Dec 3, 2018    Li.shangzhi         Create the class
 */
package com.github.icloud.elasticsearch.api.search;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders;
import org.junit.Test;
import com.github.icloud.elasticsearch.ElasticsearchClientBase;
/**
 * @FileName SearchAPI.java
 * @Description: 搜索查询，返回查询匹配的结果，搜索一个index / type 或者多个index / type
 * 
 * 官方文档 @see <a href='https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html'></a>
 * 
 * @Date Dec 3, 2018 3:31:28 PM
 * @author Li.shangzhi
 * @version 1.0
 */
public class SearchAPI extends ElasticsearchClientBase{

	@Test
	public void iEsSearch() throws Exception{
		SearchResponse response = client.prepareSearch("icloud-iot-log")	//可以是多个index
				.setTypes("icloud-auth")	//可以是多个类型
				.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
				.setQuery(QueryBuilders.termQuery("user", "ibyte"))                 // Query 查询条件
//				.setPostFilter(QueryBuilders.rangeQuery("age").from(15).to(16).includeLower(true).includeUpper(true))     // Filter 过滤
				.setPostFilter(QueryBuilders.rangeQuery("age").gte(15).lte(16))
				.setFrom(0).setSize(60).setExplain(true)
				.get();
		println(response);
	}

}
